<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('植保列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">

        <div class="col-sm-12 select-table table-striped">
            <h3 class="line">工作内容：</h3>
            <table id="bootstrap-table-1" data-mobile-responsive="true"> </table>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <h3 class="line">植保记录：</h3>&nbsp;&nbsp;
            <a class="btn btn-primary " onclick="openOrder();">
                <i class="fa fa-table"></i> 植保记录单
            </a>


            <!-- <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
                shiro:hasPermission="system:ncCheck:remove">
                 <i class="fa fa-remove"></i> 删除
             </a>-->
            <a class="btn btn-warning" onclick="confirmTable();">
                <i class="fa fa-send"></i> 确认
            </a>
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:ncZhibao:add">
                <i class="fa fa-plus"></i> 添加
            </a>

        </div>
        <div class="col-sm-12 select-table table-striped">

            <table id="bootstrap-table" data-mobile-responsive="true">
            </table>
        </div>
        <div class="bottom-btns"></div>

    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:ncZhibao:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:ncZhibao:remove')}]];
    var prefix = ctx + "system/ncZhibao";
    //施药方式
    var datas = [[${@dict.getType('executeType')}]];
    //单位
    var unit= [[${@dict.getType('unitType')}]];
    $(function() {
        var options = {
            url: prefix + "/list?conformStatus=2",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "植保",
            id: "bootstrap-table-1",
            showExport: false,
            showSearch: false,
            showRefresh: false,
            showColumns: false,
            showToggle: false,
            sortName:'createTime',
            sortOrder:'desc',
            pageSize:5,
            columns: [{
                checkbox: true
            },
                {
                    field : 'zhibaoId',
                    title : '序号',
                    visible: false
                },
                {
            title: '序号',
                formatter: function (value, row, index) {
                return $.table.serialNumber(index);
            }
        },
                {
                    field : 'planCode',
                    title : '计划编号',
                    sortable: true
                },
                {
                    field : 'cropNameCn',
                    title : '作物名称',
                    sortable: true
                },
                {
                    field : 'cropTypeCn',
                    title : '作物品种',
                    sortable: true
                },
                {
                    field : 'teamCn',
                    title : '生产班组',
                    sortable: true
                },
                {
                    field : 'planTime',
                    title : '定植/播种时间',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return dateFtt(value)
                    }
                },

                {
                    field : 'landType',
                    title : '生产大棚',
                    sortable: true,
                    formatter: function (value, row, index) {
                        if (1 == value) {
                            return "日光温室"
                        }
                        if (2 == value) {
                            return "春秋棚"
                        }
                        if (3 == value) {
                            return "连栋温室"
                        }
                        if (4 == value) {
                            return "露地"
                        }
                        return "--";
                    }
                },
                {
                    field : 'sumArea',
                    title : '种植面积(m<sup>2</sup>)',
                    sortable: true
                },
                {
                    field : 'createTime',
                    title : '提交时间',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return dateFtt(value)
                    }
                },
                {
                    field : 'createBy',
                    title : '提交人',
                    sortable: true
                },
                {
                    field : 'symptom',
                    title : '植物病症',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field : 'applicationTime',
                    title : '施药日期',
                    sortable: true
                },
                {
                    field : 'validDays',
                    title : '有效期（天）',
                    sortable: true
                },
                {
                    field : 'executeBy',
                    title : '植保人',
                    sortable: true
                },
                {
                    field : 'sourceType',
                    title : '来源',
                    sortable: true,
                    formatter: function (value, row, index) {
                        if (1 == value) {
                            return "推送"
                        }
                        if (2 == value) {
                            return "新增"
                        }
                        return "--";

                    }
                },
                {
                    field : 'remark',
                    title : '备注',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)"  onclick="confir(\'' + row.zhibaoId + '\')"><i class="fa fa-edit"></i>确认</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.zhibaoId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
        var options1 = {

        url: prefix + "/getjilulist?conformStatus=1",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "植保记录",
            showExport: false,
            showSearch: false,
            showRefresh: false,
            showColumns: false,
            showToggle: false,
            sortName:'createTime',
            sortOrder:'desc',
            pageSize:5,
            columns: [
                {
                    field : 'zhibaoId',
                    title : '编号',
                    visible: false
                },
                {
                    title: '序号',
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },

                {
                    field : 'planCode',
                    title : '计划编号',
                    sortable: true
                },
                {
                    field : 'cropNameCn',
                    title : '作物名称',
                    sortable: true
                },
                {
                    field : 'cropVarietiesCn',
                    title : '作物品种',
                    sortable: true
                },
                {
                    field : 'teamCn',
                    title : '生产班组',
                    sortable: true
                },
                {
                    field : 'planTime',
                    title : '定植/播种时间',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return dateFtt(value)
                    }
                },

                {
                    field : 'landType',
                    title : '生产大棚',
                    sortable: true,
                    formatter: function (value, row, index) {
                        if (1 == value) {
                            return "日光温室"
                        }
                        if (2 == value) {
                            return "春秋棚"
                        }
                        if (3 == value) {
                            return "连栋温室"
                        }
                        if (4 == value) {
                            return "露地"
                        }
                        return "--";
                    }
                },
                {
                    field : 'sumArea',
                    title : '种植面积(m<sup>2</sup>)',
                    sortable: true
                },
                {
                    field : 'createTime',
                    title : '提交时间',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return dateFtt(value)
                    }
                },
                {
                    field : 'createBy',
                    title : '提交人',
                    sortable: true
                },
                {
                    field : 'symptom',
                    title : '植物病症',

                    formatter: function (value, row, index) {
                        return $.table.tooltip(getText(value), 20);
                    }
                },

                {
                    field : 'causes',
                    title : '发病原因',
                    sortable: true
                },
                {
                    field : 'proposal',
                    title : '植保意见',
                    sortable: true
                },
                {
                    field : 'applicationTime',
                    title : '施药日期',
                    sortable: true
                },
                {
                    field : 'drugCode',
                    title : '药品批次号',
                    sortable: true
                },
                {
                    field : 'drugName',
                    title : '药品名称',
                    sortable: true
                },
                {
                    field : 'executeType',
                    title : '施药方式',
                    sortable: true,
                    // 格式化数据字典
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field : 'drugAmount',
                    title : '施药量',
                    sortable: true
                },
                {
                    field : 'unit',
                    title : '单位',
                    sortable: true,
                    // 格式化数据字典
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(unit, value);
                    }
                },


                {
                    field : 'validDays',
                    title : '有效期（天）',
                    sortable: true
                },
                {
                    field : 'executeBy',
                    title : '植保人',
                    sortable: true
                },
                {
                    field : 'sourceType',
                    title : '来源',
                    sortable: true,
                    formatter: function (value, row, index) {
                      if (1 == value) {
                            return "推送"
                         }
                        if (2 == value) {
                               return "新增"
                        }
                        return "--";

                     }
                },
                {
                    field : 'remark',
                    title : '备注',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.zhibaoId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.zhibaoId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options1);
    });
    var btns = [{
        name: '工作记录',
        url: ctx + 'system/ncNormalWorks?workType=10',
        id: 'normal-work'
    }]
    var btns1 = [{
        name: '消毒管理',
        url: ctx + 'system/ncXiaoduLogs',
        id: 'normal-work-1'
    }]
    addBtns(btns);
    addBtns(btns1);

    /*表单确认*/
    function confirmTable() {
        var confirmTable = prefix + "/confirmTable";
        var data = $('#bootstrap-table').bootstrapTable('getData');
        if (data && data.length > 0) {
            $.modal.confirm("确认生成植保单吗？", function () {
                var ids = [];
                    $(data).each(function (i, e) {
                        ids.push(e.zhibaoId);
                    });
                var ids_str = ids.join(",");
                myPost(confirmTable, {ids: ids_str},
                    function (data) {

                        if (data.code == 0) {
                            layer.msg("提交成功")
                        } else {
                            layer.msg(data.msg);
                        }
                        reload()
                    }, function (e) {
                        layer.msg("确认失败!");
                        reload()
                    })

            })
        } else {
            layer.msg("未发现数据!")
        }

    }
    /*打开检测记录单*/
    function openOrder() {

        var url = ctx + 'system/ncOrder?orderType=9';

        $.modal.openTab("检测记录单", url);
    }
    function reload() {
        parent.$('#bootstrap-table').bootstrapTable('refresh', {
            silent: true
        });
        parent.$('#bootstrap-table-1').bootstrapTable('refresh', {
            silent: true
        });
    }
    function confir(id){
        var url = prefix + '/enterYao/'+id;
        $.modal.open("植保用药", url);
    }
    setTitle("植保管理",false)
</script>
</body>
</html>